package com.vending.service.impl;

import com.vending.mapper.VendingMachineMapper;
import com.vending.model.entity.VendingMachine;
import com.vending.service.VendingMachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VendingMachineServiceImpl implements VendingMachineService {

    @Autowired
    private VendingMachineMapper machineMapper;

    @Override
    public List<VendingMachine> list(VendingMachine machine) {
        return machineMapper.selectList(machine);
    }

    @Override
    public VendingMachine getById(Long id) {
        return machineMapper.selectById(id);
    }

    @Override
    public void add(VendingMachine machine) {
        machine.setStatus("NORMAL"); // 新增时默认状态为正常
        machineMapper.insert(machine);
    }

    @Override
    public void update(VendingMachine machine) {
        machineMapper.updateById(machine);
    }

    @Override
    public void delete(Long id) {
        machineMapper.deleteById(id);
    }

    @Override
    public void updateStatus(Long id, String status) {
        VendingMachine machine = new VendingMachine();
        machine.setId(id);
        machine.setStatus(status);
        machineMapper.updateById(machine);
    }
} 